//
//  UILabel+rightPic.m
//  MovingLoaniOS
//
//  Created by 谷峰 on 2019/3/30.
//  Copyright © 2019 GWMFC. All rights reserved.
//

#import "UILabel+rightPic.h"
@implementation UILabel (rightPic)
- (void)stringWithImageName:(NSString *) imageName content: (NSString *)content {
    
    /// 创建一个富文本
    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:content];
    // 修改富文本中的不同文字的样式
    [attriStr addAttribute:NSForegroundColorAttributeName value:UIColor.grayColor range:NSMakeRange(0,content.length)];
    
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0,content.length)];
    
    /// 创建图片附件
    NSTextAttachment *attchImage = [[NSTextAttachment alloc] init];
    attchImage.image = [UIImage imageNamed:imageName];
    attchImage.bounds = CGRectMake(0, -1 , 13, 13);
    
    // 设置图片大小
    NSAttributedString *stringImage = [NSAttributedString attributedStringWithAttachment:attchImage];
    /// 插入图片的位置
    [attriStr appendAttributedString:stringImage];
    self.attributedText = attriStr;
    
    
}

- (void)stringWithImageName:(NSString *) imageName contentAttributedString: (NSMutableAttributedString *)content {
    
//    /// 创建一个富文本
    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithAttributedString:content];
    // 修改富文本中的不同文字的样式
    [attriStr addAttribute:NSForegroundColorAttributeName value:UIColor.grayColor range:NSMakeRange(0,content.length)];

    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0,content.length)];

//    /// 创建图片附件
    NSTextAttachment *attchImage = [[NSTextAttachment alloc] init];
    attchImage.image = [UIImage imageNamed:imageName];
    attchImage.bounds = CGRectMake(0, -1 , 13, 13);
    
    // 设置图片大小
    NSAttributedString *stringImage = [NSAttributedString attributedStringWithAttachment:attchImage];
    /// 插入图片的位置
    [content appendAttributedString:stringImage];
    self.attributedText = content;
    
    
}
@end
